mysql_connect() - Not working, probably a small error, but I just can't figure out what it is?
I'm stumped. I run the script, no errors are shown, but neither is data inserted into the DB.
Here's my code:
include("db_con.php");
$conn = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
for ($i = 1; $i <= 5; $i++) {
$urls[$i] = mysql_real_escape_string($_POST['url_' . $i]);
$names[$i] = !empty($_POST['name_' . $i]) ? mysql_real_escape_string($_POST['name_' . $i]) : mysql_real_escape_string($_POST['url_' . $i]);
}
$query = "SELECT * FROM multi_url";
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
$page_id = $num_rows++;
$query2 = "INSERT INTO multi_url (page_id, url_1, url_2, url_3, url_4, url_5, name_1, name_2, name_3, name_4, name_5) values ($page_id, $urls[1], $urls[2], $urls[3], $urls[4], $urls[5], $names[1], $names[2], $names[3], $names[4], $names[5])";
mysql_close($conn);
Any comments on the matter would be greatly 开发者_运维知识库appreciated. If there's a problem, I would've thought I'd get an error from die(mysql_error())
.
You do not send any INSERT
query to the database. You just put the SQL in a variable called $query2
.
mysql_query($query2); //sends the query to the database
That query will fail though, since none of its string columns are enclosed in quotes.
精彩评论