Jump to content

Recommended Posts

hey, newbie here

 

i am writing a code to insert some values in database, it actually worked in the afternoon, but when i started the system in the night it magically stopped working.

 

First, i am taking the value in a text box, then forwarding it to a file to be stored in a variable, then calling a function (which is in yet another file) which stores the values in the database.

 

the code is here

 

text box

<form action="add.php" method="post">
<center><input type="text" name="abc" size="9" maxlength="9">
<br><br>
<input type="submit"  value="Save">

 

to hold "abc" in a variable

 

$abc=$_POST['abc'];

add_abc($abc);

 

to insert it in a database

 

<?php
session_start();


require_once('db_fns.php');


function add_abc($abc)
{
$valid_user = $_SESSION['valid_user'];


 $conn = db_connect();
 if ($result && ($result->num_rows>0)) {
   throw new Exception('already exists.');
 }

  if (!$conn->query("insert into scores (username,abc) values
    ('".$valid_user."', '".$abc."')")) {
   throw new Exception('could not be inserted.');
 }
else { echo "successful";}
 return true;

 

 

can anyone please tell me whats wrong here??

and these are the error i get on file abc.php

 

PHP Notice: Undefined index: abc in /var/www/work/fns/add_oc_middle.php on line 5
PHP Notice: Undefined index: valid_user in /var/www/work/fns/add.php on line 13
PHP Notice: Undefined variable: result in /var/www/work/fns/add_oc_middle.php on line 16
PHP Fatal error: Uncaught exception 'Exception' with message 'Score could not be inserted.' in /var/www/work/fns/add_oc_middle.php:22
Stack trace:
#0 /var/www/work/fns/add_oc_middle.php(7): add_abc(NULL)
#1 {main}
thrown in /var/www/work/fns/add.php on line 22


Edited by sid0972

Sounds like the form isn't being posted. You need to do some debugging on your own, especially since you have only shown us snippets of the code. Walk through it and check the values at every step you can find, until you find it doesn't match your assumptions.

  • 2 weeks later...
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.