Jump to content

Recommended Posts

The following code is supposed to insert some data from the previous page into the database. It doesnt show any errors and no data goes into the database!?

 

Any

<?php

 

require_once 'mysql_connect.php';

$query = "SELECT * FROM `grahamb_test`.`schedule` WHERE `Show` = '{

$_POST["Show"]}';";

$result = mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli));

echo "rows = ".mysqli_num_rows($result);

 

if (mysqli_num_rows($result) >= 1) {

echo "This show name already exists";

 

}

else {

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` (`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` ) VALUES (NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')");

 

echo "<p>The show <b> ". $_POST["Show"] ." </b>has been added to the database!";

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/
Share on other sites

Add

 

or die("Query:{$query} Error:".mysqli_error($mysqli)); 

 

to

 

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` 
(`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` )
VALUES
(NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')");

 

 

That would tell you have a missing comma here

 

$_POST["EndTime"]."''".$_POST["Day"].

 

You could actually write this query like this:

 

$sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` 
( `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` )
VALUES
('{$_POST["Show"]}','{$_POST["StartTime"]}','{$_POST["EndTime"]}','{$_POST["Day"]}','{$_POST["Type"]}','{$_POST["Page"]}','{$_POST["Profile_url"]}')");

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.